/*
 * @Description:基础表格数据类 rule 行规则 fileInfo文件库信息 rowData 行数据
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2022-11-29 12:27:14
 * @LastEditors: swc
 * @LastEditTime: 2024-06-19 10:10:49
 */
/* eslint-disable max-classes-per-file */

import { I_fv, I_rule } from '../../../ifs';
import { T_rule } from './rule';

export class T_baseData {
  // 行数据规则
  rule: I_rule;

  // 每行数据系统默认字段_file_info_id_存放文件库id
  // 通过文件库信息表达来操作文件库
  // 文件库常用于行附件，图片，缩略图的需求
  fileInfo: object = {};

  // 行数据为一个{field:"字段名",value:"字段值"}数组
  rowData: I_fv[];

  constructor() {
    this.rowData = [] as I_fv[];
    this.rule = new T_rule();
  }

  /**
   * @description: 设置行规则
   * @param {object} p规则对象
   * @return {this}返回本类实例
   * @author: wiz
   * @Date: 2022-12-01 11:10:53
   * @LastEditors: wiz
   * @LastEditTime: Do not edit
   */
  public setDataRule(p: I_rule): T_baseData {
    this.rule = p;
    return this;
  }

  /**
   * @description: 设置行数据
   * @param {I_fv} p T_fv
   * @return {this}返回本类实例
   * @author: wiz
   * @Date: 2022-12-01 11:10:53
   * @LastEditors: wiz
   * @LastEditTime: Do not edit
   */
  public setRowData(...p: I_fv[]): T_baseData {
    if (Array.isArray(p)) {
      p.forEach(el => {
        // el.value !== null && this.rowData.push(el);
        this.rowData.push(el);
      });
    }
    return this;
  }

  /**
   * @description: 设置文件信息
   * @param {I_fv} p 文件对象
   * @return {this}返回本类实例
   * @author: wiz
   * @Date: 2022-12-01 11:06:37
   * @LastEditors: wiz
   */
  public setFileInfo(p: object): T_baseData {
    this.fileInfo = p;
    return this;
  }
}
export interface I_baseData extends T_baseData {}
